package main

import "fmt"

func main() {
	height := []int{1, 8, 6, 2, 5, 4, 8, 3, 7}
	v := maxArea(height)
	fmt.Println(v)
}

func maxArea(height []int) int {
	l := 0
	r := len(height) - 1

	mostVal := (r - l) * min(height[l], height[r])
	for l < r {
		if height[l] < height[r] {
			l++
		} else {
			r--
		}
		mostVal = max(mostVal, (r-l)*min(height[l], height[r]))
	}
	return mostVal
}

func min(v1, v2 int) int {
	if v1 < v2 {
		return v1
	}
	return v2
}

func max(v1, v2 int) int {
	if v1 > v2 {
		return v1
	}
	return v2
}
